package org.wu.reggie.mapper;

import org.apache.ibatis.annotations.*;
import org.wu.reggie.entity.Category;

import java.util.List;

public interface CategoryMapper {


    @Insert("insert into category values(null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Category category);

    @Select("select count(*) from category where name = #{name}")
    Integer findByName(String name);

    // 查询所有的类别
    @Select("select * from category order by sort")
    List<Category> findAll();


    // 根据id删除分类
    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);

    @Update("update category set type=#{type},name=#{name},sort=#{sort},update_time = #{updateTime} where id = #{id}")
    void updateById(Category category);

    List<Category> list(@Param("type") Integer type);

    @Select("select * from category where id = #{id}")
    Category findById(Long categoryId);
}
